/* eslint valid-jsdoc: "off" */

"use strict";

/**
 * @param {Egg.EggAppInfo} appInfo app info
 */
const path = require("path");
module.exports = appInfo => {
  /**
   * built-in config
   * @type {Egg.EggAppConfig}
   **/
  const config = (exports = {});

  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + "_1695039219042_2923";

  // add your middleware config here

  config.space = init_space(appInfo);
  config.middleware = [];
  config.multipart = {
    mode: "file",
  };
  config.sequelize = init_mysql(appInfo);
  config.security = {
    csrf: {
      enable: false,
    },
  };
  config.view = {
    mapping: {
      ".html": "ejs",
    },
  };
  config.io = {
    init: {},
    namespace: {
      "/": {
        connectionMiddleware: ["connection"],
        packetMiddleware: ["packet"],
      },
    },
  };
  config.bodyParser = {
    enable: true,
    encoding: "utf8",
    formLimit: "100kb",
    jsonLimit: "100kb",
    strict: true,
    // @see https://github.com/hapijs/qs/blob/master/lib/parse.js#L8 for more options
    queryString: {
      arrayLimit: 100,
      depth: 5,
      parameterLimit: 1000,
    },
    enableTypes: ["json", "form", "text"],
    extendTypes: {
      text: ["text/xml", "application/xml"],
    },
  };
  // add your user config here
  const userConfig = {
    // myAppName: 'egg',
  };
  return {
    ...config,
    ...userConfig,
  };
};
function init_space(app) {
  let public_url = "http://192.168.1.104:7005";
  let dev_public = "D:\\public"
  let prod = {
    tv_img_space: "E:\\public\\tv_img",
    movie_img_space: "E:\\public\\movie_img",
    ffmpeg_path: "D:\\util\\ffmpeg5.1\\bin\\ffmpeg.exe",
    tv_path: "E:\\public\\tv",
    movie_path: "E:\\public\\movie",
    public_url: public_url,
    public_tv_img: `${public_url}/tv_img/`,
    public_movie_img: `${public_url}/movie_img/`,
    public_movie_space: `${public_url}/movie/`,
    public_tv_space: `${public_url}/tv/`,
  }
  let dev = {
    tv_img_space: `${dev_public}\\tv_img`,
    movie_img_space: `${dev_public}\\movie_img`,
    ffmpeg_path: "D:\\util\\ffmpeg5.1\\bin\\ffmpeg.exe",
    tv_path: `${dev_public}\\tv`,
    movie_path: `${dev_public}\\movie`,
    public_url: public_url,
    public_tv_img: `${public_url}/tv_img/`,
    public_movie_img: `${public_url}/movie_img/`,
    public_movie_space: `${public_url}/movie/`,
    public_tv_space: `${public_url}/tv/`,
  }
  return app.env == "prod" ? prod : dev;
}
function init_mysql(app) {
  let prod = {
    dialect: "mysql",
    host: "127.0.0.1",
    port: 3306,
    database: "film_db",
    user: "root",
    password: "123123",
    query: {
      raw: true,
    },
  };
  let dev = {
    dialect: "mysql",
    host: "127.0.0.1",
    port: 3306,
    database: "film_db_test",
    user: "root",
    password: "123123",
    query: {
      raw: true,
    },
  };
  return app.env == "prod" ? prod : dev;
  // return prod;
}
